home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
034a
/
twview82.zip
/
CONVERT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-02-04
|
7KB
|
263 lines
{ Part one will parse a log file, and store explored sectors; then
create a text file that you can feed to the computer that will give you
a map of the universe. Part two will take a log file generated from
feeding the first to the computer, and create a data file that can
be fed into something else.
}
program converter;
{$I headers.inc}
const
Version = ' dos 0.82b';
var
filename : string;
errorCode,
n : integer;
f, g : text;
space : TheVoid;
function ReadNumber : integer;
{ Read the next number from text file f. If there is no next number,
return 0.}
var
number : integer;
ch : char;
i : integer;
begin
number := 0;
if not eof( f ) then
begin
read( f, ch );
while (ch in [' ',#9, #10, #13]) and (not eof(f)) do read( f, ch );
repeat
if ch in ['0'..'9'] then
number := number * 10 + ord( ch ) - ord( '0' );
if not eof( f ) then
read( f, ch )
else
ch := #26;
until (not (ch in ['0'..'9']));
if ch = '[' then {hit [PAUSE]^h^h^h^h^h^h^h}
for i := 1 to 32 do
read(f, ch);
end;
ReadNumber := number;
end;
procedure skip( var f : text; n : integer);
var
ch : char;
begin
for n := 1 to n do
read( f, ch );
end; {skip}
{$I gsdata.inc }
procedure PartI;
var
newcount,
count, n : integer;
line : string;
ch : char;
begin
newcount := 0;
repeat
readln( f, line );
until (pos( 'sectors:', line ) > 0) or eof( f );
n := readNumber;
count := 0;
while (not eof( f )) and (n>0) do
begin
count := count + 1;
if space.sectors[n].number = 0 then
begin
newcount := newcount + 1;
writeln('New sector info for ', n );
writeln( g, 'I', n );
writeln( g, 'R', n );
end; {if}
n := readNumber;
end; {while}
writeln('You have explored ', count, ' sectors.');
writeln('Explored ', newcount, ' new sectors.');
write('Do you want a refresh on your ports? ');
readln( ch );
if ch in ['Y','y'] then
for n := 1 to maxSector do
if space.sectors[n].PortType <> NotAPort then
writeln( g, 'R', n );
close( g );
end; {PartI}
procedure LoadData( var TheSector : SectorInfo );
var
ch : char;
begin
with TheSector do
begin
number := 0;
repeat
read( f, ch );
until ch = ':';
ch := '-';
while ch = '-' do
begin
number := number + 1;
data[ number ] := ReadNumber;
read( f, ch );
end; {while}
readln( f );
end; {with}
end; {LoadData}
procedure CheckData( var TheSector : SectorInfo );
var
t : warpIndex;
ch : char;
begin
repeat
read( f, ch );
until ch = ':';
for t := 1 to TheSector.number do
begin
if TheSector.data[ t ] <> ReadNumber then
begin
write('Log data doesn''t match input data! Exiting without save!');
halt;
end; {if}
read( f, ch );
end; {for}
readln( f );
end; {Data}
procedure ProcessWarps( var space : TheVoid );
var
s : integer;
line : string;
begin
skip( f, 6);
s := ReadNumber;
writeln('Processing sector ', s );
if s = 0 then
begin
writeln('Something is screwy. Exiting.');
readln;
writeln('Screwup after line:');
writeln( line );
readln;
SaveData( g, space );
readln;
halt;
end;
if space.sectors[s].number > 0 then
CheckData( space.sectors[ s ] )
else
LoadData( space.sectors[ s ] );
end; {ProcessWarps}
{$I PortStat.inc }
{$I status.inc }
procedure ProcessPorts( var space : TheVoid;
line : string );
var
LeftBrack, s : integer;
ch : char;
err : string;
begin
LeftBrack := pos( ']', line );
delete( line, 1, LeftBrack );
if bval( line, s ) then
writeln('error parsing sector ', line )
else if (s<1) or (s>maxSector) then
writeln('sector value', s, ' out of bounds ')
else if not eof( f ) then
begin
readln( f ); { next line is blank }
if not eof( f ) then
begin
readln( f, line );
if (copy( line, 1, 8) = 'Commerce') and (not eof( f )) then
begin
if pos( 'Stargate Alpha', line ) > 0 then
begin
writeln('StarDock found in sector ', s);
space.dock := s;
space.sectors[ s ].etc := space.sectors[ s ].etc or StarDock;
end;
space.sectors[ s ].etc := space.sectors[ s ].etc or IsPort;
GetPortStatus( s, space.sectors[ s ].portType, line, space.Ports );
writeln('Status on port ', s, ' : ', status(space.sectors[s].portType) );
end {if}
else
space.sectors[s].portType := NotAPort;
end; {if}
end; {eof}
end; {ProcessPorts}
procedure PartII( var space : TheVoid );
var
line : string;
ch : char;
s, i : integer;
finished : boolean;
begin
while not eof( f ) do
begin
readln( f, line );
if pos( 'examine?', line ) > 0 then
processWarps( space )
else if pos( 'What sector is the port in?', line) > 0 then
processPorts( space, line );
end; {while}
writeln('Log processed... updating now.');
SaveData( g, space );
end; {PartII}
{$I part3.inc}
{$I part4.inc}
begin {main}
writeln('Tradewars Data Base generator: version', Version);
writeln;
GetData( space );
writeln('Choices:');
writeln(' (1) Read "Explored Sectors" list for newly scanned sectors');
writeln(' (2) Read log files for inter-warp and port information');
writeln(' (3) Read "Unexplored Sectors" list for newly scanned sectors');
writeln(' (4) Read "Fighter Display" list for fighter clouds');
writeln;
write('Your choice? (1, 2, 3, or 4) ');
readln( n );
repeat
case n of
1 : write('Name of "Explored Sectors" file? ');
2 : write('Name of log file? ');
3 : write('Name of "Unexplored Sectors" file? ');
4 : write('Name of "Deployed Fighter Scan" file? ');
end; {case}
readln( filename );
if filename = '' then
halt;
{$I-}
assign( f, filename);
reset( f );
{$I+}
errorCode := ioResult;
if errorCode <> 0 then writeln('Error ', errorCode, ' opening file!');
until errorCode = 0;
write('Name of file to generate? ');
readln( filename );
assign( g, filename );
rewrite( g );
case n of
1 : partI;
2 : partII( space);
3 : partIII;
4 : partIV( space );
end; {case}
close( f );
end.